#!/usr/bin/env bash

# GNU version
alias diff="diff --color=auto" # GNU diffutils required (brew install diffutils)
alias df="gdf -h"
alias du="gdu -h"
alias grep="ggrep --color=auto"
alias chmod="gchmod --preserve-root -v"
alias chown="gchown --preserve-root -v"
alias find="gfind"

# General
alias cp="cp -iv"
alias mv="mv -iv"
alias md="mkdir -pv"
alias rm="rm -iv"
alias c="clear"
alias ka="killall"

# ls
alias ls="gls -hFN --color=auto --group-directories-first --hyperlink=auto" # Use GNU ls (brew install coreutils)
alias la="ls -A"
alias l="ls -l"
alias ll="l -A"
alias lr="l -R"  # recursive
alias lk="l -Sr" # sort by size, largest last
alias lm="l -tr" # sort by modification time, i.e., mtime, newest last
alias lc="lm -c"  # sort by change (status) time, i.e., ctime, newest last
alias lx="l -X"  # sort by extension

# Tmux
alias s="tmux-sessionizer"

# brew
alias bu="brew update"
alias bU="brew upgrade"
alias bls="brew list"

# Misc
alias t="trash" # trash is ~/.config/zsh/functions/trash
alias sc="shellcheck"
alias iina="open -a 'IINA'"
alias highlight="highlight --out-format=truecolor --force -s darkplus"
alias ncdu="ncdu --color dark -rr -x --exclude .git --exclude node_modules"

# Kitty
alias kcat="kitty +kitten icat"

# Download
alias wget="wget --continue --progress=bar --timestamping"
alias curl="curl --continue-at - --location --progress-bar --remote-name --remote-time"
alias aria="aria2c --max-connection-per-server=5 --continue"
alias yd="yt-dlp --paths ~/Downloads"
alias yda="yt-dlp --extract-audio --audio-format best --paths ~/Downloads"

# Use neovim for vim if present
command -v nvim >/dev/null && alias vimdiff="nvim -d"

# Dotfiles management
alias dot="git --git-dir=$HOME/dotfiles/ --work-tree=$HOME"

# Convert video to GIF (with 2K resolution) using ffmpeg
# Usage: vtg input_name output_name, then output_name.gif will be generated
alias vtg='function video_to_gif(){ ffmpeg -i $1 -pix_fmt rgb8 -r 10 -vf scale=2560:-1 $2.gif && gifsicle -O3 $2.gif -o $2.gif && osascript -e "display notification \"$2.gif successfully converted and saved\" with title \"VIDEO2GIF SUCCESS!\""};video_to_gif'

# "ranger" is an autoload function defined at ../functions/ranger
# When quitting ranger using Z, change the shell pwd to the last visited directory
alias ra="ranger"

# Quick navigation (J for Jump)
alias Jo="cd ~/Documents"
alias Jl="cd ~/Downloads"
alias Jb="cd ~/Library/CloudStorage/Dropbox/"
alias Jg="cd ~/gitrepos"
alias Jp="cd ~/projects"
alias Jc="cd ~/.config"
alias Jv="cd ~/.config/nvim"
